// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-04-19 22:58
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.Object_;

import java.util.Arrays;
import java.util.Scanner;

public class SimBag {
    public static final int INF = Integer.MIN_VALUE;

    /*
        简单背包问题模拟
     */
    public static void main(String[] args) {
        Scanner myScannrt = new Scanner(System.in);
        int n = myScannrt.nextInt();
        int[][] t = new int[n][2];
        int v = myScannrt.nextInt();
        for (int i = 0; i < n; i++) {
            t[i][0] = myScannrt.nextInt();
            t[i][1] = myScannrt.nextInt();
        }
        // 降维状态数组
        int[] f = new int[v + 1];
        Arrays.fill(f, INF);
        f[0] = 0;

        for (int i = 1; i <= n; i++) {
            int cost = t[i - 1][0], w = t[i - 1][1];
//            for (int j = cost; j <= v; ++j) {
//                f[j] = Math.max(f[j], f[j - cost] + w);
//            }

            for (int j = v; j >= cost; j--) {
                f[j] = Math.max(f[j], f[j - cost] + w);
            }
        }
        System.out.println(f[v]);

//        int[][] f = new int[n + 1][v + 1];
//        for (int i = 1; i <= n; i++) {
//            int cost = t[i - 1][0], w = t[i - 1][1];
//            for (int j = cost; j <= v; j++) {
//                f[i][j] = Math.max(f[i - 1][j], f[i - 1][j - cost] + w);
//            }
//        }
//        System.out.println(f[n][v]);
/*
4 5
1 2
2 4
3 4
4 5


5 20
1 2
2 4
3 4
5 4
4 5
 */
    }

}
